home *** CD-ROM | disk | FTP | other *** search
- X-Mailer: Mozilla 2.0 (X11; I; SunOS 5.5 sun4m)
- MIME-Version: 1.0
- Subject: Re: Randomness
- References: <451.6681T677T994@summat.demon.co.uk>
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- Path: imada.ou.dk!breese
- From: breese@imada.ou.dk (Bjorn Reese)
- Message-ID: <1996Apr19.105527.4477@imada.ou.dk>
- Sender: news@imada.ou.dk
- Nntp-Posting-Host: gounod.imada.ou.dk
- Organization: Dept. of Math. & Computer Science, Odense University, Denmark
- Date: Fri, 19 Apr 1996 10:55:27 GMT
- Newsgroups: comp.sys.amiga.programmer
-
- Mike Dodd wrote:
- > "FastRand" :
- [...]
- > but this produces a rather poor sequence of values...Soooerh, any better
- > suggestions ?
-
- Yes, FastRand does exceptionally bad when RandomSeed is less than
- $80000000.
-
- Try this one. Sorry about the C. It should be very easily translated
- though. If you find InitRandom() too hard to translate, you can just
- just FastRand (with RandomSeed > $80000000) to fill in rndValues.
-
- /* RNDSIZE must be an integral number of 2 (and at least 8) */
- #define RNDSIZE 64
- #define RNDMASK (RNDSIZE - 1)
- typedef unsigned long RND;
-
- static short rnd1;
- static short rnd2;
- static RND rndValues[RNDSIZE];
-
- inline RND Random(void)
- {
- rnd1 = (rnd1 - 1) & RNDMASK;
- rnd2 = (rnd2 - 1) & RNDMASK;
- return (rndValues[rnd2] += rndValues[rnd1]);
- }
-
- void InitRandom(int s)
- {
- int i;
-
- for (i = 0; i < RNDSIZE; i++) {
- rndValues[i] = (RND)s;
- /* --- randqd1() from Numerical Recipes --- */
- s = 0x0019660dL * s + 0x3c6ef35fL;
- }
- rnd1 = 0;
- rnd2 = RNDSIZE/2 - 3;
-
- /* --- Remove initial errors of bad seeding (warn-up) --- */
- for (i = 0; i < RNDSIZE; i++) Random();
- }
-
- --
- Bjorn Reese Email: breese@imada.ou.dk
- Odense University, Denmark URL: http://www.imada.ou.dk/~breese
-
- "It's getting late in the game to show any pride or shame" - Marillion
-